package ec.cd.processor.gui;

import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PanelChooseFile extends JPanel {
	private JTextField textPath;
	private JButton buttonChooseFile;
	private File fileChosen;
	private JLabel labelName;
	/**
	 * Create the panel.
	 */
	public PanelChooseFile(String name) {
		super();
		labelName = new JLabel(name);
		this.setLayout(new FlowLayout());
		textPath = new JTextField(15);
		textPath.setEditable(false);
		this.add(labelName);
		this.add(textPath);
		buttonChooseFile = new JButton("Browse...");
		buttonChooseFile.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.showDialog(null, "Load");
				setFileChosen(fileChooser.getSelectedFile());
				if(getFileChosen() != null){
					 textPath.setText(getFileChosen().getAbsolutePath());
				}
			}
		});
		this.add(buttonChooseFile);
		//this.setSize(230, 30);
		this.setVisible(true);
	}
	public File getFileChosen() {
		return fileChosen;
	}
	public void setFileChosen(File fileChosen) {
		this.fileChosen = fileChosen;
	}

}
